package 挤牛奶;

import java.util.*;

public class Main {
    static int N = 5010;
    static PII[] p = new PII[N];

    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int n = in.nextInt();
        for (int i = 0; i < n; i++) {
            int l = in.nextInt();
            int r = in.nextInt();
            p[i] = new PII(l, r);
        }
        Arrays.sort(p, 0, n);
        int l = p[0].l, r = p[0].r, res1 = 0, res2 = 0;
        for (int i = 1; i < n; i++) {
            if (p[i].l <= r) {
                r = Math.max(r, p[i].r);
            } else {
                res1 = Math.max(res1, r - l);
                res2 = Math.max(res2, p[i].l - r);
                l = p[i].l;
                r = p[i].r;
            }
        }
        res1 = Math.max(res1, r - l);
        System.out.println(res1 + " " + res2);
    }
}

class PII implements Comparable<PII> {
    int l, r;

    public PII(int l, int r) {
        this.l = l;
        this.r = r;
    }

    @Override
    public int compareTo(PII o) {
        return Integer.compare(this.l, o.l);
    }
}
